package com.example.dw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.dw.entity.ActivityComment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 活动评论Mapper接口
 * @author system
 * @since 2024-01-01
 */
@Mapper
public interface ActivityCommentMapper extends BaseMapper<ActivityComment> {

    /**
     * 根据活动ID分页获取评论（带用户信息）
     */
    @Select("SELECT ac.*, u.username, u.nickname, u.avatar " +
            "FROM activity_comment ac " +
            "LEFT JOIN user u ON ac.userid = u.userid " +
            "WHERE ac.activityid = #{activityid} " +
            "ORDER BY ac.createdAt DESC " +
            "LIMIT #{offset}, #{size}")
    List<ActivityComment> getCommentsByActivityId(@Param("activityid") Integer activityid,
                                                  @Param("offset") Integer offset,
                                                  @Param("size") Integer size);

    /**
     * 根据活动ID获取评论总数
     */
    @Select("SELECT COUNT(*) FROM activity_comment WHERE activityid = #{activityid}")
    Integer getCommentCountByActivityId(@Param("activityid") Integer activityid);

    /**
     * 根据活动ID获取所有评论（带用户信息）- Web版
     */
    @Select("SELECT ac.*, u.username, u.nickname, u.avatar " +
            "FROM activity_comment ac " +
            "LEFT JOIN user u ON ac.userid = u.userid " +
            "WHERE ac.activityid = #{activityid} " +
            "ORDER BY ac.createdAt DESC")
    List<ActivityComment> getAllCommentsByActivityId(@Param("activityid") Integer activityid);

    /**
     * 根据活动ID获取平均评分
     */
    @Select("SELECT AVG(stars) FROM activity_comment WHERE activityid = #{activityid}")
    Double getAverageStarsByActivityId(@Param("activityid") Integer activityid);
} 